<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>会员列表-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
		<meta name="renderer" content="webkit" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
		<link rel="stylesheet" href="../../static/css/font.css" />
		<link rel="stylesheet" href="../../static/css/weadmin.css" />
		<link rel="stylesheet" href="https://unpkg.com/element-ui@2.13.1/lib/theme-chalk/index.css">
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
		  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
		  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
		<![endif]-->
		<script src="../../../../assets/js/vendor/vue.min.js"></script>
		<script src="../../../../assets/js/vendor/jquery-3.3.1.min.js"></script>
		<script src="https://unpkg.com/element-ui@2.13.1/lib/index.js"></script>
		<script src="../../../../assets/js/plugins/utils.js"></script>
	</head>

	<body>
		<div class="weadmin-nav">
			<span class="layui-breadcrumb">
				<a href="javascript:;">首页</a> <a href="javascript:;">会员管理</a>
				<a href="javascript:;"> <cite>会员列表</cite></a>
			</span>
			<a class="layui-btn layui-btn-sm" style="margin-top:3px;float:right" href="javascript:location.replace(location.href);"
			 title="刷新">
				<i class="layui-icon layui-icon-refresh"></i>
				<!-- <i class="layui-icon" style="line-height:30px">&#x1002;</i> -->
			</a>
		</div>

		<div class="weadmin-body" id="memberList">
			<div class="layui-row">
				<div class="layui-form layui-col-md12 we-search">
					会员搜索：
					<div class="layui-inline">
						<input class="layui-input" placeholder="开始日" name="start" id="start" />
					</div>
					<div class="layui-inline">
						<input class="layui-input" placeholder="截止日" name="end" id="end" />
					</div>
					<div class="layui-inline">
						<input type="text" name="email" id="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input" />
					</div>
					<button class="layui-btn" @click="search()">
						<i class="layui-icon layui-icon-search"></i>
					</button>
				</div>
			</div>
			<div class="weadmin-block">
				<button class="layui-btn" onclick="WeAdminShow('添加用户','./add.html',600,400)">
					<i class="layui-icon layui-icon-add-circle-fine"></i>添加
				</button>
				<span class="fr" style="line-height:40px">共有数据：{{page.total}} 条</span>
			</div>
			<table class="layui-table">
				<thead>
					<tr>
						<th>ID</th>
						<th>姓名</th>
						<th>邮箱</th>
						<th>加入时间</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<tr :data-id="index+1" v-for="(user,index) in userList"  v-if="userList!=''">
						<td>{{index+1}}</td>
						<td>{{user.nickname}}</td>
						<td>{{user.email}}</td>
						<td>{{user.createtime}}</td>
						<td class="td-manage">
							<a title="删除" @click="deleteUser(user, index)" href="javascript:;">
								<i class="layui-icon layui-icon-delete"></i>
							</a>
						</td>
					</tr>
				</tbody>
			</table>
			<div class="block">
				<el-pagination
						@current-change="handleCurrentChange"
						:current-page.sync="page.pageNum"
						:page-size="page.pageSize"
						:hide-on-single-page="true"
						layout="total, prev, pager, next"
						:total="page.pages">
				</el-pagination>
			</div>
		</div>
		<!--<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>-->
		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		<script src="../../static/js/eleDel.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var user_list = new Vue({
				el: "#memberList",
				data: {
					userList: [],
					page: {"pageNum": 1, "pageSize": 10, "pages": 0, "total": 0}
				},
				mounted: function () {
					console.log(this);
					this.getUserList();
				},
				methods: {
					getUserList() {
						$.ajax({
							url: "/admin/user_list/"+this.page.pageNum,
							type: "GET",
							headers: {
								"Authorization": "Bearer " + handleLocalStorage("get", "token")
							},
							success: function (response) {
								if (response.code == 200) {
									user_list.userList=response.data.list;
									user_list.page.pageNum = response.data.pageNum;
									user_list.page.pageSize = response.data.pageSize;
									user_list.page.pages = response.data.pages;
									user_list.page.total = response.data.total;
									console.log(user_list.userList);
								}else {
								}
							},
							error: function (error) {
								alert("服务器错误");
							}

						});
					},
					deleteUser(user, index) {
						var t = this;
						$.ajax({
							url: "/admin/user_delete/"+user.id,
							type: "GET",
							headers: {
								"Authorization": "Bearer " + handleLocalStorage("get", "token")
							},
							success: function (response) {
								alert(response.message);
								if (response.code == 200) {
									user_list.getUserList();
								}
							},
							error: function (error) {
								alert("服务器错误");
							}
						});
					},
					search() {
						this.page.pageNum = 1;
						var start = $("#start").val();
						var end = $("#end").val();
						var email = $("#email").val();
						console.log(start);
						$.ajax({
							url: "/admin/user_search?start="+start+"&end="+end+"&email="+email+"&pageNum=1",
							type: "GET",
							headers: {
								"Authorization": "Bearer " + handleLocalStorage("get", "token")
							},
							success: function (response) {
								if (response.code == 200) {
									user_list.userList=response.data.list;
									user_list.page.pageNum = response.data.pageNum;
									user_list.page.pageSize = response.data.pageSize;
									user_list.page.pages = response.data.pages;
									user_list.page.total = response.data.total;
									console.log(response);
								}else {
								}
							},
							error: function (error) {
								alert("服务器错误");
							}

						});
					},
					handleCurrentChange(val) {
						this.page.pageNum = val;
						this.getUserList();
					}
				}
			});
		</script>
	</body>
</html>
